export default {
    data() {
        return {
            apiUrl: {
                // 登录
                userLogin: 'http://cmsapi.55duanzi.com/api/user/login',

                // CPA数据管理
                customerSearch: '/cpa/api/customer/search',
                customerNew: '/cpa/api/customer/new',
                customerGet: '/cpa/api/customer/get',
                customerGetAlias: '/cpa/api/customer/getAlias',
                customerUpdate: '/cpa/api/customer/update',
                customerProSearch: '/cpa/api/customer_product/search',
                customerProListLight: '/cpa/api/customer_product/list_light',
                customerProNew: '/cpa/api/customer_product/new',
                customerProGet: '/cpa/api/customer_product/get',
                customerProUpdate: '/cpa/api/customer_product/update',
                customerProductDel: '/cpa/api/customer_product/del',
                customerProListBiztype: '/cpa/api/customer_product/list_biztype',
                customerProListPackage: '/cpa/api/customer_product/list_package',
                customerProUpdatePackage: '/cpa/api/customer_product/update_package_price',
                channelSearch: '/cpa/api/channel/search',
                channelNew: '/cpa/api/channel/new',
                channelGet: '/cpa/api/channel/get',
                channelGetAlias: '/cpa/api/channel/getAlias',
                channelUpdate: '/cpa/api/channel/update',
                channelProSearch: '/cpa/api/channel_product/search',
                channelProNew: '/cpa/api/channel_product/new',
                channelProGet: '/cpa/api/channel_product/get',
                channelProUpdate: '/cpa/api/channel_product/update',
                channelProUpdatePackPrice: '/cpa/api/channel_product/update_package_price',
                channelProDel: '/cpa/api/channel_product/del_product',
                channelProDelNew: '/cpa/api/channel_product/del',
                channelProList: '/cpa/api/channel_product/list_product',
                channelProListPack: '/cpa/api/channel_product/list_product_package',
                channelProListCustomer: '/cpa/api/channel_product/list_customer',
                channelProListPackage: '/cpa/api/channel_product/list_package',
                channelProSearchByPackageCode: '/cpa/api/channel_product/searchByPackageCode',
                realtimeSearch: '/cpa/api/realtime/search',
                realtimeRefresh: '/cpa/api/realtime/refresh',
                realtimeDelete: '/cpa/api/realtime/delete',
                realtimeBatch_del: '/cpa/api/realtime/batch_del',
                realtimeUpdateAct: '/cpa/api/realtime/updateAct',
                realtimeUpdateChannel: '/cpa/api/realtime/updateChannel',
                createBill: '/cpa/api/bill/create_bill',
                getCustomerBill: '/cpa/api/bill/bill_detail?type=1',
                getChannelBill: '/cpa/api/bill/bill_detail?type=2',
                financeInfoBill: '/cpa/api/bill/finance_info',
                customerBillList: '/cpa/api/bill/list_customer_bill',
                channelBillList: '/cpa/api/bill/list_channel_bill',
                customerBillDel: '/cpa/api/bill/del_customer_bill',
                channelBillDel: '/cpa/api/bill/del_channel_bill',
                txList: '/cpa/api/tx/list',
                txDetail: '/cpa/api/tx/detail',
                txCreate: '/cpa/api/tx/create',
                dingGetTxList: '/cpa/api/tx/getTxList',
                lockStatus: '/cpa/api/bill/lock_status',
                customerBillQuickCreate: '/cpa/api/bill/quick_create_customer_bill',
                channelBillQuickCreate: '/cpa/api/bill/quick_create_channel_bill',
                billStatConsume: '/cpa/api/bill/stat_consume',
                billDetail: '/cpa/api/bill/bill_detail',
                uploadApk: process.env.VUE_APP_BASE_URL + '/cpa/api/upload/uploadApk',
                uploadData: process.env.VUE_APP_BASE_URL + '/cpa/api/realtime/import',
                uploadCustomer: process.env.VUE_APP_BASE_URL + '/cpa/api/customer/import',
                uploadChannel: process.env.VUE_APP_BASE_URL + '/cpa/api/channel/import',
                uploadChannelProduct: process.env.VUE_APP_BASE_URL + '/cpa/api/channel_product/import_v2',
                uploadCustomerProduct: process.env.VUE_APP_BASE_URL + '/cpa/api/customer_product/import',
                importdataGetCookie: '/cpa/api/importdata/get_tt_cookie',
                importdataStartFetch: '/cpa/api/importdata/start_fetch',
                importGetCaptcha: '/cpa/api/importdata/get_captcha'
            }
        };
    },
    methods: {
        //标准时间转常用格式
        formatDateTime(date, format) {
            if (!date) {
                return '';
            }
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            h = h < 10 ? ('0' + h) : h;
            minute = minute < 10 ? ('0' + minute) : minute;
            second = second < 10 ? ('0' + second) : second;
            if (format == 'y-m-d h-m-s') {
                return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
            } else if (format == 'h-m') {
                return ' ' + h + ':' + minute;
            }else if (format ==  'y-m-d h-m') {
                return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
            } else if (format == 'y-m-d') {
                return y + '-' + m + '-' + d;
            } else if (format == 'y/m/d') {
                return y + '/' + m + '/' + d;
            } else if (format == 'ymd') {
                return y + '' + m + '' + d;
            } else if (format == 'y-m') {
                return y + '-' + m;
            }
        },
        // 导出xls数据
        handleDownload(theader, filterval, tabledata, filename) {
            this.downloadLoading = true;
            require.ensure([], () => {
                const {
                    export_json_to_excel
                } = require('@/vendor/Export2Excel');
                const tHeader = theader;
                const filterVal = filterval;
                const list = tabledata;
                const data = this.formatJson(filterVal, list);
                export_json_to_excel(tHeader, data, filename);
                this.downloadLoading = false;
            });
        },
        formatJson(filterVal, jsonData) {
            return jsonData.map(v => filterVal.map(j => v[j]));
        },
        //cpa信息、产品上传成功提示
        handleSuccess(res) {
            this.loading = false;
            res.error = res.error.replace(/\|/g, '<br>');
            res.msg = res.msg.replace(/\|/g, '<br>');
            let html = `
                <div style="margin-bottom: 10px;"><b>总共导入条数：</b>${res.num}</div>
                <div style="margin-bottom: 10px;">
                    <b>导入提示：</b>
                    <div>${res.msg || '无'}</div>
                </div>
                <div>
                    <b>导入错误：</b>
                    <div>${res.error || '无'}</div>
                </div>
                `;
            this.importTitleTxt = html;
            this.importTitleStatus = true;
        },
        // cpa信息、产品上传错误
        uploadError() {
            this.loading = false;
            this.$message({
                type: 'error',
                message: '上传失败，请重试'
            });
        },
        // cpa信息、产品上传时
        uploading() {
            this.loading = true;
        },
        // cpa信息、产品上传前对文件的大小的判断
        beforeAvatarUpload(file) {
            var fileName = file.name.split('.');
            var fileNameLen = fileName.length - 1;
            const extension = fileName[fileNameLen] === 'csv';
            if (!extension) {
                this.$message({
                    type: 'info',
                    message: '上传渠道包只能是 csv 格式'
                });
            }
            return extension;
        },
    }

};